package com.example.administrator.testproject.MVP.Progress;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.example.administrator.testproject.Common.Constant;
import com.example.administrator.testproject.MVP.Base.BaseActivity;
import com.example.administrator.testproject.R;
import com.example.administrator.testproject.Wiget.ProgressActivity;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/10/24 0024.
 */

public class TestMainActivity extends BaseActivity {

    @BindView(R.id.stack_progress)
    ProgressActivity stackProgress;

    @Override
    protected int setContentViews() {
        return R.layout.progress_layout;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showProgress();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000 * 2);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            hideProgress();
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000 * 2);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            toError();
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000 * 2);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            toEmpty();
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public void toError(){
        stackProgress.showError(getResources().getDrawable(R.mipmap.ic_launcher), Constant.ERROR_TITLE, Constant.ERROR_CONTEXT, Constant.ERROR_BUTTON, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                stackProgress.showLoading();
                //重试
            }
        });
    }
    public void toEmpty(){
        stackProgress.showEmpty(getResources().getDrawable(R.mipmap.ic_launcher), Constant.EMPTY_TITLE_BOOKS, Constant.EMPTY_CONTEXT_BOOKS);
    }

    public void showProgress() {
        stackProgress.showLoading();
    }

    public void hideProgress() {
        stackProgress.showContent();
    }
}
